﻿using System.Diagnostics.CodeAnalysis;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Radzen;

namespace Swimj.RazorLib.Partials
{
    public partial class SearchFormPartial<T> : ComponentBase
    {
        [Inject]
        [NotNull]
        public NotificationService? NotificationService { get; set; }

        [Parameter] public int ItemXsSize { get; set; } = 12;

        [Parameter] public int ItemMdSize { get; set; } = 6;

        [Parameter] public int ItemLgSize { get; set; } = 3;

        [Parameter][NotNull] public T? Model { get; set; }

        [Parameter] public Func<MouseEventArgs, Task>? QueryHandler { get; set; }

        protected async Task GridQueryButtonClick(MouseEventArgs args)
        {
            try
            {
                if (QueryHandler != null)
                {
                    await QueryHandler.Invoke(args);
                }
            }
            catch (Exception ex)
            {
                NotificationService.Notify(new NotificationMessage
                {
                    Severity = NotificationSeverity.Error,
                    Summary = $"Error",
                    Detail = $"Unable to query"
                });
            }
        }
    }
}